import org.spark.example.ClazzTest

import scala.io.StdIn

object Test{
    def main(args: Array[String]): Unit = {
        println("test")

        val buf = new StringBuilder;
        buf += 'a';
        buf ++= "bcd";
        buf.append("ef");
        println(buf);
        println(buf.length)

        val c = new ClazzTest(3, 5);
        println(c.add());
        val alice = new Person("Alice", 25)
        val bob = new Person("Bob", 32)
        val charlie = new Person("Charlie", 32)

        for (person <- List(alice, bob, charlie)) {
            person match {
                case Person("Alice", 25) => println("Hi Alice!")
                case Person("Bob", 32) => println("Hi Bob!")
                case Person(name, age) =>
                    println("Age: " + age + " year, name: " + name + "?")
            }
        }

        val x = Test(5)
        println(x)

        x match
        {
            case Test(num) => println(x + " 是 " + num + " 的两倍！")
            //unapply 被调用
            case _ => println("无法计算")
        }

        val test = Set("a", "a", "c", "b");
        println(test);
    }
    // 样例类
    case class Person(name: String, age: Int)

    def apply(x: Int) = x*2
    def unapply(z: Int): Option[Int] = if (z%2==0) Some(z/2) else None
}